package com.itheima.nio.tomcat.handler;

import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;

public class AcceptHandler {

    public SocketChannel connectSocketChannel(SelectionKey selectionKey){
        try{
            ServerSocketChannel serverSocketChannel = (ServerSocketChannel) selectionKey.channel();
            SocketChannel socketChannel = serverSocketChannel.accept();
            socketChannel.configureBlocking(false);
            Selector selector = selectionKey.selector();
            socketChannel.register(selector, SelectionKey.OP_READ);

        } catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

//    public SocketChannel connectSocketChannel1(SelectionKey selectionKey){
//        SocketChannel socketChannel = null;
//        try{
//            ServerSocketChannel serverSocketChannel = (ServerSocketChannel) selectionKey.channel();
//            socketChannel = serverSocketChannel.accept();
//            socketChannel.configureBlocking(false);
//            Selector selector = selectionKey.selector();
//            socketChannel.register(selector, SelectionKey.OP_READ);
//
//        } catch (Exception e){
//            e.printStackTrace();
//        }
//        return socketChannel;
//    }
}
